package com.handinglian.task.enums;

public enum OrderEnum {
    UNKNOWN(0,""),
    ASC(1,"正序"),
    DESC(2,"倒叙");

    public static OrderEnum valueOfOrdinal(Integer ordinal) {
        return ordinal == null || ordinal >= values().length ? UNKNOWN : values()[ordinal];
    }
    public static OrderEnum valueOfDesc(String desc) {
        for(OrderEnum orderEnum: OrderEnum.values()){
            if(desc.equals(orderEnum.getDescription())){
                return orderEnum;
            }
        }
        return UNKNOWN;
    }
    public static OrderEnum valueOfKey(Integer key){
        for(OrderEnum orderEnum : OrderEnum.values()){
            if(orderEnum .getKey()==key){
                return orderEnum;
            }
        }
        return UNKNOWN;
    }
    private final Integer key;
    private final String description;

    OrderEnum(Integer key, String description) {
        this.key = key;
        this.description = description;
    }

    public Integer getKey() {
        return key;
    }
    public String getDescription() {
        return this.description;
    }
}
